home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 23 / CU Amiga - Super CD-ROM 23 (June 1998).iso / CreatingGames / Utilities / Amos / SupraProcs / ClipBob.AMOS / ClipBob.amosSourceCode < prev    next >
Encoding:
AMOS Source Code  |  1996-01-26  |  3.2 KB  |  95 lines

  1. '   ******************************************************** 
  2. '   ***                                                  *** 
  3. '   ***                Clip Bob Procedure                *** 
  4. '   ***                                                  *** 
  5. '   ***                        by                        *** 
  6. '   ***                                                  *** 
  7. '   ***                   Joseph Bolin                   *** 
  8. '   ***                                                  *** 
  9. '   ******************************************************** 
  10.  
  11. Screen Open 0,320,200,4,Lowres
  12. Flash Off 
  13. Palette $0,$FFF,$80,$800
  14. Paper 2 : Pen 1 : Curs Off 
  15. Cls 2 : Ink 0 : Bar 0,0 To 15,15
  16. Get Bob 1,0,0 To 64,64
  17. Cls 0
  18. Ink 3
  19. Bar 0,88 To 319,Screen Height-1
  20. Paste Bob 0,0,1
  21. Locate 2,4 : Print "Orig."
  22. Paste Bob 0,100,1
  23. Paper 3 : Locate 2,21 : Print "Copy"
  24. Paper 0 : Locate 0,9 : Centre "Press a key"
  25. Wait Key 
  26. Pen 0 : Locate 0,9 : Centre "           "
  27. _CLIPBOB[1,16,16,47,47,0]
  28. _CLIPBOB[1,6,6,15,15,1]
  29. Paste Bob 128,100,1
  30. Paper 3 : Locate 17,21 : Print "Masked"
  31.  
  32. Procedure _CLIPBOB[_BOB,_XSTART,_YSTART,_XEND,_YEND,_MASK]
  33.    
  34.    ' Inputs:  _BOB       =Bob to make/erase mask on; To mask an icon, use a minus value   
  35.    '          _XPOS,_YPOS=Coordinates of upper-left of section to mask      
  36.    '          _XEND,_YEND=Corrdinates of lower-right of section to mask 
  37.    '          _MASK      =Flag:0=Make section transparent, 1=Make section opaque    
  38.    '
  39.    ' Output:  Make a section of a bob or icon either transparent or opaque  
  40.  
  41.  
  42.    If _BOB>=0 Then SBASE=Sprite Base(_BOB) : MBASE=Sprite Base(-_BOB)
  43.    If _BOB<0 Then SBASE=Icon Base(-_BOB) : MBASE=Icon Base(_BOB)
  44.    If SBASE=0 and _BOB>=0 Then Error 68
  45.    If SBASE=0 and _BOB<0 Then Error 74
  46.    If MBASE<0 and _BOB>=0 Then Make Mask _BOB : MBASE=0
  47.    If MBASE<0 and _BOB<0 Then Make Icon Mask -_BOB : MBASE=0
  48.    If MBASE=0 and _BOB>=0 Then Paste Bob -999,-999,_BOB : MBASE=Sprite Base(-_BOB)
  49.    If MBASE=0 and _BOB<0 Then Paste Icon -999,-999,-_BOB : MBASE=Icon Base(_BOB)
  50.    SWIDTH=Deek(SBASE)*2
  51.    SHEIGHT=Deek(SBASE+2)
  52.    CH:
  53.    If _XSTART<0 Then _XSTART=0
  54.    If _XEND<_XSTART Then Swap _XEND,_XSTART : Goto CH
  55.    CH2:
  56.    If _YSTART<0 Then _YSTART=0
  57.    If _YEND<_YSTART Then Swap _YEND,_YSTART : Goto CH2
  58.    If _XSTART>=SWIDTH*8 Then _XSTART=SWIDTH*8-1
  59.    If _XEND>=SWIDTH*8 Then _XEND=SWIDTH*8-1
  60.    If _YSTART>=SHEIGHT Then _YSTART=SHEIGHT-1
  61.    If _YEND>=SHEIGHT Then _YEND=SHEIGHT-1
  62.    LEFT=(_XSTART+7)/8 : RIGHT=(_XEND+1)/8
  63.    TP=_YSTART : BOTTOM=_YEND
  64.    If RIGHT<=LEFT or BOTTOM=TP Then Goto LFT
  65.    For Y=TP To BOTTOM
  66.       AD=MBASE+4+Y*SWIDTH+LEFT
  67.       For X=1 To RIGHT-LEFT
  68.          If _MASK=0 Then Poke AD,0 Else Poke AD,255
  69.          Inc AD
  70.       Next 
  71.    Next 
  72.    LFT:
  73.    LBIT=_XSTART and 7
  74.    If LBIT=0 Then Goto RGT
  75.    BT=256
  76.    For B=1 To LBIT
  77.       BT=BT/2
  78.    Next 
  79.    Dec BT : AD=MBASE+4+TP*SWIDTH+LEFT-1
  80.    For Y=0 To BOTTOM-TP
  81.       If _MASK=0 Then Poke AD,Peek(AD) and 255-BT : Else Poke AD,Peek(AD) or BT
  82.       Add AD,SWIDTH
  83.    Next 
  84.    RGT:
  85.    RBIT=_XEND and 7 : If RBIT=7 or RIGHT<=LEFT Then Pop Proc
  86.    BT=256
  87.    For B=0 To RBIT
  88.       BT=BT/2
  89.    Next 
  90.    BT=256-BT : AD=MBASE+4+TP*SWIDTH+RIGHT
  91.    For Y=0 To BOTTOM-TP
  92.       If _MASK=0 Then Poke AD,Peek(AD) and 255-BT : Else Poke AD,Peek(AD) or BT
  93.       Add AD,SWIDTH
  94.    Next 
  95. End Proc